package com.nuo.test.classloader;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;

public class ClassLoaderTest2 {
	public static void main(String[] args) throws MalformedURLException, ClassNotFoundException {
		System.out.println(ClassLoaderTest2.class.getClassLoader());
		System.out.println();
		new ClassLoaderTest2().loaderOtherClass();
		new ClassLoaderTest2().loaderOtherClass2();
		
	}
	
	
	public void loaderOtherClass() throws MalformedURLException, ClassNotFoundException{
		File file = new File("E:\\new_ws\\taoyf-case\\classloader");
		
		MyClassLoader loader = new MyClassLoader(new URL[]{file.toURI().toURL()}, this.getClass().getClassLoader());
		Class clazz = loader.loadClass("com.nuo.util.Abcd");
		System.out.println(clazz.getClassLoader());
		
		MyClassLoader loader2 = new MyClassLoader(new URL[]{file.toURI().toURL()}, this.getClass().getClassLoader());
		Class clazz2 = loader2.loadClass("com.nuo.util.Abcd");
		System.out.println(clazz2.getClassLoader());
		
		System.out.println(clazz.equals(clazz2));
		
	}
	
	public void loaderOtherClass2() throws MalformedURLException, ClassNotFoundException{
		File file = new File("E:\\new_ws\\taoyf-case\\classloader");
		
		MyClassLoader loader = new MyClassLoader(new URL[]{file.toURI().toURL()}, this.getClass().getClassLoader());
		Class clazz = loader.loadClass("com.nuo.util.ClassUtil");
		System.out.println(clazz.getClassLoader());
		
		MyClassLoader loader2 = new MyClassLoader(new URL[]{file.toURI().toURL()}, this.getClass().getClassLoader());
		Class clazz2 = loader2.loadClass("com.nuo.util.ClassUtil");
		System.out.println(clazz2.getClassLoader());
		
		System.out.println(clazz.equals(clazz2));
		
	}
}
